package com.lagou.rabbitmq.demo.listener;

import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.messaging.handler.annotation.Payload;
import org.springframework.stereotype.Component;

import java.io.UnsupportedEncodingException;

@Component
public class MyMessageListener {


    /*一个消息只能有一个监听，不然报错
    @RabbitListener(queues = "queue.anno")
    public void whenMessageCome(Message message) throws UnsupportedEncodingException {
        System.out.println(new String(message.getBody(),message.getMessageProperties().getContentEncoding()));
    }*/

    @RabbitListener(queues = "queue.anno")
    public void whenMessageCome(@Payload String messageStr) throws UnsupportedEncodingException {
        System.out.println(messageStr);
    }
}
